/**
 * Show Navigation Map:No
 * 
 * Check point: No boxes appear
 * 
 * Steps: 1.Page1 answer, check the navigation map(should can't find).
 * 2.Lead to Page2 no answer, check the navigation map(should can't find).
 * 3.Lead to Page3 answer, check the navigation map(should can't find).
 */
package com.tcc.assessment.studentrole.shownavigationmap;

import org.apache.commons.io.FileUtils;
import org.apache.xpath.operations.String;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.tcc.assessment.logic.Playback;
import com.tcc.qa.test.util.BaseTest;
import com.tcc.qa.test.util.JudgeWebElement;
import com.tcc.qa.test.util.SelLogger;

/**
 * @company CampusCruiser
 * @author Emily_Wang
 * @date 2012-8-9
 */
public class Assessment27 extends BaseTest{
//This string is the Xpath of the page location.
 String PageXpath = "//div[@id='questionContainer']/form/div/table/tbody/tr[1]/td[3]";

 // This string is the Xpath of the title location.
 String TitleXpath = "//div[@id='questionContainer']/form/div/table/tbody/tr[1]/td[1]/h1";
 int errorCount = 0;
 // Initialization Log
 private static final SelLogger logger = SelLogger.getLogger(Assessment27.class);

 @Test(description = "Goto My Assessment Page and Start Session", priority = 1)
 public void setUp() throws InterruptedException {
   Playback.initPlaybacker(getWebDriver(), "Assessment27");
   }
 @Test(description = "Page1", priority = 2)
 public void page1() throws InterruptedException {
   getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
   Playback.switchWindow(getWebDriver());
   Playback.getShortAnswerObj(getWebDriver(), 2).sendKeys("2");
   Playback.getChooseOneAsnwerObj(getWebDriver(), 3, 4).click();
   Assert.assertTrue(getWebDriver().findElement(By.xpath(PageXpath)).getText().contains("Page 1 of 3"), "Page1 >> Pagination info is incorrect!");
   Assert.assertTrue(getWebDriver().findElement(By.xpath(TitleXpath)).getText().contains("Assessment27"), "Page1 >> Page Title is incorrect!");
   if(!JudgeWebElement.doesWebElementExist(getWebDriver(), By.id("assessmentContentNav"))){
     logger.pass("Page1 >> can't find the Navigation map as expected.");
   }
   else{
     logger.error("Page1 >> can find the Navigation map, but should not.");
   }
   this.screenShot(getWebDriver(), "Assessment27");
   Playback.goNextPlaybackPage(getWebDriver());
 }
 @Test(description = "Page2", priority = 3)
 public void page2() throws InterruptedException {
   getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
   Playback.switchWindow(getWebDriver());
   Assert.assertTrue(getWebDriver().findElement(By.xpath(PageXpath)).getText().contains("Page 2 of 3"), "Page1 >> Pagination info is incorrect!");
   Assert.assertTrue(getWebDriver().findElement(By.xpath(TitleXpath)).getText().contains("Assessment19"), "Page1 >> Page Title is incorrect!");
   if(!JudgeWebElement.doesWebElementExist(getWebDriver(), By.id("assessmentContentNav"))){
     logger.pass("Page2 >> can't find the Navigation map as expected.");
   }
   else{
     logger.error("Page2 >> can find the Navigation map, but should not.");
   }
   Playback.goNextPlaybackPage(getWebDriver());
 }
 @Test(description = "Page3", priority = 4)
 public void page3() throws InterruptedException {
   getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
   Playback.switchWindow(getWebDriver());
   Playback.getShortAnswerObj(getWebDriver(), 1).sendKeys("6");
   for (int i = 0; i < 5; i++) {
     Playback.getMatchingOneObj(getWebDriver(), 2, i + 1).sendKeys(String.valueOf(i + 1));
   }
   Assert.assertTrue(getWebDriver().findElement(By.xpath(PageXpath)).getText().contains("Page 3 of 3"), "Page1 >> Pagination info is incorrect!");
   Assert.assertTrue(getWebDriver().findElement(By.xpath(TitleXpath)).getText().contains("Assessment19"), "Page1 >> Page Title is incorrect!");
   if(!JudgeWebElement.doesWebElementExist(getWebDriver(), By.id("assessmentContentNav"))){
     logger.pass("Page3 >> can't find the Navigation map as expected.");
   }
   else{
     logger.error("Page3 >> can find the Navigation map, but should not.");
   }
 }
     private WebDriver screenShot(WebDriver driver, String screenshotName) {
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss SS");
       Calendar ca = Calendar.getInstance();
       try {
         File screenshotFile = ((TakesScreenshot) driver)
             .getScreenshotAs(OutputType.FILE);
         FileUtils.copyFile(screenshotFile, new File("logs//TestReport//TestImg//"
             + screenshotName + sdf.format(ca.getTime()) + ".png"));
       } catch (Exception e) {
         e.printStackTrace();
       }
       return driver;
     }
   
 
}
